import request from '@/utils/request.js'
import { useTokenStore } from "@/stores/token.js";

//文章分类查询
//查询时需要从 pinia 中 获取登录获得的 JWT令牌
export const articleCategoryListService = () => {
    //实例一个 pinia
    const tokenStore = useTokenStore();
    // alert(tokenStore.token);
    //获取token
    //tokenStore.token

    //在 pinia定义的响应式数据 可以不用.value ，可以直接使用
    //return request.get('/category',{headers:{'Authorization':tokenStore.token}})
    return request.get('/api/category')
}


//export 把函数暴露出去
//文章分类添加
export const articleCategoryAddService = (categoryData) => {
    return request.post('/api/category', categoryData);
}

//文章分类修改 update
export const articleCategoryUpdateService = (categoryData) => {
    return request.put('/api/category', categoryData);
}

//文章分类删除 delete
export const articleCategoryDeleteService = (id) => {
    return request.delete('/api/category?id=' + id);
}

//获取文章详情 get(id) list 
export const articleListService = (params) => {
    //return request.get('/article?pageNum=' + pageNum+'&pageSize='+pageSize+'&categoryId='+categoryId+'&state='+state);
    // return request.get('/article?pageNum=' + pageNum+'&pageSize='+pageSize);
    return request.get('/api/article',{params:params})
}

//文章添加
export const articleAddService = (articleData) =>{
    return request.post('/api/article',articleData);
}



//搜题获取题目和答案get(id) list 
export const searchForAnswer = (params) => {
    //return request.get('/article?pageNum=' + pageNum+'&pageSize='+pageSize+'&categoryId='+categoryId+'&state='+state);
    // return request.get('/article?pageNum=' + pageNum+'&pageSize='+pageSize);
    // return axios({
    //     url: '/api',
    //     method: 'get',
    //     data: JSON.stringify(params),
    //     headers: {
    //       'Content-Type': 'application/json'
    //     },
    //   })
    return request.get('/search',{params:params})
}
